/**
 * 视频详情 Tab 页面
 * Create by Songlcy
 */
import 'package:flutter/material.dart';
import 'package:scoped_model/scoped_model.dart';

import '../../common/status.dart';
import '../../utils/time_util.dart';

import '../../models/pood/video_model.dart';
import '../../models/pood/video_detail_model.dart';
import '../../models/state_model/video_detail_state_model.dart';

import '../../components/tag_component.dart';
import '../../components/loading_component.dart';
import '../../components/data_empty_component.dart';
import '../../components//video_detail_item_component.dart';

class VideoDescTabPage extends StatelessWidget {

  final VideoModel videoModel;
  const VideoDescTabPage(this.videoModel);

  @override
  Widget build(BuildContext context) {
    return ScopedModelDescendant<VideoDetailStateModel>(
      builder: (context, child, model) {
        VideoDetailModel? videoDetailModel = model.videoDetailModel;
        if(model.status == Status.LOADING) {
          return LoadingComponent();
        }else if(model.status == Status.SUCCESS) {
          return ListView(
            children: <Widget>[
              VideoDetailItemComponent(
                icon: "assets/images/icon_videodetail_name.png",
                content: "${videoModel.name}",
                child: TagComponent(
                    title: videoDetailModel!.classify.name
                ),
              ),
              Container(
                  margin: EdgeInsets.symmetric(vertical: 13.0),
                  child: VideoDetailItemComponent(
                      icon: "assets/images/icon_videodetail_director.png",
                      content: "导演: ${videoDetailModel.director[0]}"
                  )
              ),
              VideoDetailItemComponent(
                  icon: "assets/images/icon_videodetail_starring.png",
                  content: "明星主演"
              ),
              Container(
                margin: EdgeInsets.fromLTRB(33.3, 8.0, 16.0, 0.0),
                child: Text("${videoDetailModel.starring.getRange(
                    0, videoDetailModel.starring.length)}"),
              ),
              Container(
                  margin: EdgeInsets.symmetric(vertical: 13.0),
                  child: VideoDetailItemComponent(
                      icon: "assets/images/icon_videodetail_num.png",
                      content: "${videoModel.latest}"
                  )
              ),
              VideoDetailItemComponent(
                  icon: "assets/images/icon_videodetail_jishu.png",
                  content: "[ 更新时间 ] ${TimeUtil.getTimeago(
                      DateTime.parse(videoModel.generatedAt))}"
              ),
            ],
          );
        }else {
          return DataEmptyComponent(status: model.status);
        }
      },
    );
  }
}
